/**
 * mock 工具集
 */
const { Random } = require('mockjs');

const Utils = {
  setRes(options = {}) {
    const { code = Random.int(0, 5) >= 1 ? 1 : 0, message, data = {}, totalCount = 1 } = options;
    const result = {
      code,
      message: message || ['失败', '错误', '异常'][Random.integer(0, 2)],
      data,
      totalCount,
    };
    return result;
  },
  setSuccessRes(data, totalCount) {
    return this.setRes({
      code: 1,
      message: '成功',
      data,
      totalCount,
    });
  },
  setFailedRes(data, totalCount) {
    return this.setRes({
      code: 0,
      message: '失败',
      data,
      totalCount,
    });
  },
  setSimpleRes(data) {
    return data;
  },
};

module.exports = Utils;
